<%#
  # WebROaR - Ruby Application Server - http://webroar.in/
  # Copyright (C) 2009  Goonj LLC
  #
  # This file is part of WebROaR.
  #
  # WebROaR is free software: you can redistribute it and/or modify
  # it under the terms of the GNU General Public License as published by
  # the Free Software Foundation, either version 3 of the License, or
  # (at your option) any later version.
  #
  # WebROaR is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  # GNU General Public License for more details.
  #
  # You should have received a copy of the GNU General Public License
  # along with WebROaR.  If not, see <http://www.gnu.org/licenses/>.
  #%>

<% if type == "Edit" %>
  <% url = {:controller => 'application_specification', :action => 'edit_application', :id => params[:id]} %>
<% else %>
  <% url = {:controller => 'application_specification', :action => 'add_application'} %>
<% end %>
<%= form_remote_for :application_specification, :url => url, :html => { :onsubmit => 'if(!validate_application(this)){return false;}'} ,:before => "show_busy_div()", :complete => "hide_busy_div(request)", :update => "application_specification_form" do %>	
  <div class = "text_align_center" >
    <table width = 60% align='center'>
      <tr>
        <th colspan = 2><%= type %> Application</th>
      </tr>
      <tr>
        <td colspan = 2 id = 'error_div' style="padding:0px;">
          <% if @application_specification.errors.any? %>
            <h2><%= pluralize(@application_specification.errors.count, "error") %> prohibited this entry from being saved:</h2>
            <ul>
              <% @application_specification.errors.full_messages.each do |msg| %>
                <li><%= msg %></li>
              <% end %>
            </ul>
          <% end %>
        </td>
      </tr>
      <tr>
        <td>Application Name<span id = 'needed'>*</span></td>
        <% if controller.action_name == "edit_application_form" or controller.action_name == "edit_application" %>
          <td > <%= @application_specification.name%><%=hidden_field :application_specification, :name %></td>
        <% else %>     
          <td><%= text_field :application_specification, :name, :size => 20, :tabindex => "1" %></td>
        <% end %>
      </tr>
      <tr>
        <td>Resolver<span id = 'needed'>*</span> &nbsp;&nbsp;&nbsp;
            <%= link_to_function "Help",:onclick => "addHelp('resolver',event)" %>
        </td>
        <td><%= text_field :application_specification, :resolver, :size => 20, :tabindex => "2" %></td>
      </tr>
      <tr>
        <td>Path<span id = 'needed'>*</span> &nbsp;&nbsp;&nbsp;
            <%= link_to_function "Help", :onclick=>"addHelp('path',event)" %>
        </td>
        <td ><%= text_field :application_specification, :path, :size => 20, :tabindex => "3" %></td>
      </tr>
      <tr>
        <td>RunAsUser<span id = 'needed'>*</span> &nbsp;&nbsp;&nbsp;
            <%= link_to_function "Help", :onclick => "addHelp('runasuser',event)" %>
        </td>
        <td><%= text_field :application_specification, :run_as_user, :size=>20, :tabindex => "4" %></td>
      </tr>
      <tr>
        <td>Type &nbsp;&nbsp;&nbsp;
            <%= link_to_function "Help", :onclick => "addHelp('type',event)" %>
        </td>
        <td><%= select :application_specification, :type1,%w{Rails Rack}, {}, {:onChange => 'disableAnalytics(this.value);', :tabindex => "5"} %></td>
      </tr>
      <tr>
        <td>Analytics &nbsp;&nbsp;&nbsp;
            <%= link_to_function "Help", :onclick => "addHelp('analytics',event)" %>
        </td>
        <td><%= select :application_specification, :analytics, @analytics, {}, {:tabindex => "6"} %></td>
      </tr>
      <tr>
        <td>Environment</td>
        <td><%= text_field :application_specification, :environment, :size => 20, :tabindex => "7" %></td>
      </tr>
      <tr>
        <td>Minimum number of workers &nbsp;&nbsp;&nbsp;			
            <%= link_to_function "Help", :onclick => "addHelp('app_minworker',event)" %>
        </td>
        <td ><%=text_field :application_specification, :min_worker, :size=>20, :tabindex => "8", :value => @application_specification.min_worker.to_i %></td>
      </tr>
      <tr>
        <td>Maximum number of workers &nbsp;&nbsp;&nbsp;
            <%= link_to_function "Help", :onclick => "addHelp('app_maxworker',event)" %>
        </td>
        <td ><%=text_field :application_specification, :max_worker, :size => 20, :tabindex => "9" , :value => @application_specification.max_worker.to_i %></td>
      </tr>
      <tr>
        <%if type == "Edit"%>
          <td colspan = 2 style="text-align:center;"><%= hidden_field :application_specification, :app_id %>
          <%= submit_tag 'Save and Restart', :tabindex => "10" %></td>
        <%else%>			
          <td colspan = 2 style="text-align:center;"><%=hidden_field :application_specification, :app_id %>
          <%= submit_tag 'Deploy', :tabindex => "10" %></td>
        <%end%>	
      </tr>	
      <tr>
        <td colspan = 2 ><%= link_to 'Back', configuration_path, :tabindex => "11" %></td>
      </tr>	
    </table>
  </div>
<% end %>
